import {
  Entity,
  PrimaryGeneratedColumn,
  OneToMany,
  Column,
  ManyToOne,
  ManyToMany,
  TreeChildren,
  TreeParent,
  Tree,
} from 'typeorm';
import { RouteEntity } from '../route/route.entity';

@Entity({ name: 'menu' })
@Tree('closure-table')
export class MenuEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column('varchar')
  name: string;

  @Column('varchar')
  icon: string;

  @Column('int')
  type: number;

  @Column('datetime')
  createDate: string;

  @ManyToOne(
    () => RouteEntity,
    route => route.menus,
  )
  route: RouteEntity;

  @TreeChildren({ cascade: true })
  children: MenuEntity[];

  @TreeParent({ onDelete: 'CASCADE' })
  parent: MenuEntity;
}
